Note
Go to the end to download the full example code.
Calculate the ground states of a 2d quantum Ising model using threading
Calculate the ground states of a 2d quantum Ising model using threading to parallelize within one machine.
# pylint: disable=invalid-name
import numpy as np
import qtealeaves as qtl
from qtealeaves.models import get_quantum_ising_2d
def main(tn_type=5, input_folder=None, output_folder=None):
"""
Main method for the ground state simulation of a
quantum Ising model in 2D. This setup uses threading
on the python side.
**Arguments**
tn_type : int, optional
Choose 5 for python-TTN, 6 for python-MPS.
Default to 5.
input_folder : str | None, optional
Input folder. Default to None.
output_folder : str | None, optional
Output folder. Default to None.
"""
gfields = np.linspace(0, 2, 21)
if input_folder is None:
input_folder = lambda params: "QI2d/input_g%2.4f" % (params["g"])
if output_folder is None:
output_folder = lambda params: "QI2d/output_g%2.4f" % (params["g"])
model, my_ops = get_quantum_ising_2d()
my_conv = qtl.convergence_parameters.TNConvergenceParameters(
max_iter=5, max_bond_dimension=16
)
my_obs = qtl.observables.TNObservables()
simulation = qtl.QuantumGreenTeaSimulation(
model,
my_ops,
my_conv,
my_obs,
tn_type=tn_type,
folder_name_input=input_folder,
folder_name_output=output_folder,
has_log_file=True,
store_checkpoints=False,
)
params = []
for gfield in gfields:
params.append(
{
"L": 8,
# model parameters
"J": 1.0,
"g": gfield,
}
)
simulation.run(params, delete_existing_folder=True, nthreads=8)
for elem in params:
results = simulation.get_static_obs(elem)
print(
"TTN ground state energy is %4.8f at field g=%2.4f"
% (results["energy"], elem["g"])
)
print(f"\nExample `{__file__}` ran successfully; no asserts implemented.")
return
if __name__ == "__main__":
main()